<?php

Raise::load('core.cache.RaiseFileCache');
Raise::load('core.io.file.RaisePath');
Raise::load('core.security.RaiseHashDigest');
Raise::load('core.datetime.RaiseTimeSpan');

/**
 * TestCoreRaisefileCache class
 * Testing unit of 'phpraise/core/RaiseCache.php'
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaisefileCache extends RaiseTest {

    public static function testClass(){

        self::assertClassExists('RaiseFileCache');
        self::assertClassExists('RaiseCacheDriver');
        self::assertClassExtends('RaiseFileCache', 'RaiseCacheDriver');
        self::assertClassMethod('RaiseFileCache', array(
            'save',
            'load',
            'folder',
            'delete',
            'clear',
            'query',
            'file',
            'expiry'
        ));
    }

    public static function testSavingCache(){
        $cache = new RaiseFileCache('testingCache', new RaiseTimeSpan(3600));
        self::assertObjectClass($cache, 'RaiseFileCache');

        self::assertObjectClass($cache->file(), 'RaiseFile');

        $s = 'testing content';
        $cache->save($s);
        self::assertObjectClass($cache->expiry(), 'RaiseDateTime');
        self::assertTrue($cache->expiry()->toTimestamp() > time());

        $path = RaisePath::combine(RaiseFileCache::folder(), RaiseHashDigest::sha256($cache->id()));
        self::assertFileExist($path);
        self::assertStrictEqual($cache->load(), $s);

        unlink($path);
    }

}


